home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdarg.h>
- #include <string.h>
- #include <unistd.h>
- #include <malloc.h>
- #include <math.h>
- #include <sys/stat.h>
-
- #include <X11/Intrinsic.h>
- #include <X11/StringDefs.h>
- #include <X11/cursorfont.h>
- #include <X11/SGIScheme.h>
- #include <Xm/Xm.h>
- #include <Xm/MwmUtil.h>
- #include <Xm/CascadeB.h>
- #include <Xm/Form.h>
- #include <Xm/Frame.h>
- #include <Xm/Label.h>
- #include <Xm/MainW.h>
- #include <Xm/MessageB.h>
- #include <Xm/PushB.h>
- #include <Xm/RowColumn.h>
- #include <Xm/Separator.h>
- #include <Xm/Text.h>
- #include <Xm/ToggleB.h>
- #include "Row.h"
-
- #include "vroom.h"
- #include "body.h"
- #include "track.h"
- #include "ogl.h"
- #include "car.h"
- #include "solo.h"
- #include "framerate.h"
- #include "playmode.h"
- #include "client.h"
- #include "sound.h"
- #include "messages.h"
-
- #if !defined(VROOM_DEFAULT_DIR)
- #define VROOM_DEFAULT_DIR "."
- #endif /* VROOM_DEFAULT_DIR */
-
- #if !defined(VROOM_DEFAULT_REC_DIR)
- #define VROOM_DEFAULT_REC_DIR "."
- #endif /* VROOM_DEFAULT_REC_DIR */
-
- #define MAX_VISIBLE_HELP_LINES 24
-
-
- /* BEGIN PROTOTYPES -S vroom.c */
- static void calculateFrameRate( void ) ;
- static Widget createHelpWidget( Widget parent, char *helpMessage,
- XtCallbackProc nextHelp, char **helpFileName ) ;
- static void createIntroWindow( Widget parent ) ;
- static void createMainWindow( Widget parent, Dimension w, Dimension h ) ;
- static Widget createMenu( Widget menuBar, char *label ) ;
- static Widget createScrolledTextDialog( Widget parent, char *helpMessage,
- XtCallbackProc nextHelp, char **helpFileName ) ;
- static void destroyWidgetCB( Widget w, XtPointer clientData,
- XtPointer callData ) ;
- static void determineMyName( void ) ;
- static void getDefaultDataDir( void ) ;
- static char * getHelpMessage( char *file ) ;
- static void initSound( void ) ;
- static Boolean masterWorkProc( XtPointer clientData ) ;
- static int numberOfLines( const char *text ) ;
- static void showMessage( char *msg, unsigned char dialogType,
- XtCallbackProc callback, XtPointer userData ) ;
- /* END PROTOTYPES -S vroom.c */
-
-
- static String fallbacks[] = {
- "*overlayFont: -*-helvetica-bold-r-normal--20-*",
- "*msgLabel.overlayFont: -*-helvetica-medium-r-normal--18-*",
- "Vroom.geometry: +100+100",
- "*keyboardFocusPolicy: pointer",
- "*useSchemes: true",
- "*sgiMode: true",
- /* Below in case schemes & sgiMode is off */
- "*fontList: -*-helvetica-bold-r-normal--14-*",
- "*foreground: black",
- "*background: #aaaaaa",
- "*highlightColor: white",
- NULL
- } ;
-
- char *basename = "vroom" ;
- char *myName = "me" ;
- char *defaultDataDir ;
- char *defaultRecDir ;
- int freeTime = 1 ;
- int nPlayers = 1 ;
- int nCars = 1 ;
- int self = 0 ;
- int playMode = VROOM_NO_MODE ;
- int showSpeedBars = 1 ;
- long myHostId = 0 ;
- float currentTime = 0.0f ;
- float frameRate = 0.0f ;
- float speedFactor = 1.0f / TOP_SPEED ;
- Widget topLevel ;
- Widget mainWindow = NULL ;
- Widget introWindow = NULL ;
- Widget messageForm ;
- Widget playModeForm ;
- Widget localCourseForm ;
- Widget serverCourseForm ;
- Widget serverForm ;
- Widget resultsForm ;
- Widget previewForm ;
- Widget skillForm ;
- Widget courseVoteForm ;
- Widget nameForm ;
- Widget msgLabel ;
- XtAppContext appContext ;
- PlayerStruct player[MAX_PLAYERS] ;
-
- extern int debugOn ;
-
- static int startedX = 0 ;
- static int workProcMask = 0 ;
- static XtWorkProcId lastWorkProc = 0 ;
-
-
- typedef struct {
- Boolean audio ;
- char *name ;
- char *defaultDataDir ;
- char *defaultRecDir ;
- int ttl ;
- Dimension mainWidth ;
- Dimension mainHeight ;
- } AppData, *AppDataPtr ;
-
- AppData AppRes ;
-
- static XtResource resources[] = {
- { "audio", "Audio", XtRBoolean, sizeof(Boolean),
- XtOffset( AppDataPtr, audio ), XtRString, "True" },
- { "name", "Name", XtRString, sizeof( char * ),
- XtOffset( AppDataPtr, name ), XtRString, "" },
- { "defaultDataDir", "DefaultDataDir", XtRString,
- sizeof( char * ), XtOffset( AppDataPtr, defaultDataDir ),
- XtRString, "" },
- { "defaultRecDir", "DefaultRecDir", XtRString,
- sizeof( char * ), XtOffset( AppDataPtr, defaultRecDir ),
- XtRString, "" },
- { "ttl", "Ttl", XtRInt, sizeof(int),
- XtOffset( AppDataPtr, ttl ), XtRString, "8" },
- { "mainWidth", "MainWidth", XtRDimension, sizeof(Dimension),
- XtOffset( AppDataPtr, mainWidth ), XtRString, "600" },
- { "mainHeight", "MainHeight", XtRDimension, sizeof(Dimension),
- XtOffset( AppDataPtr, mainHeight ), XtRString, "600" },
- } ;
-
- Sfx alertSfx ;
- Sfx changeLaneSfx ;
- Sfx cheerSfx ;
- Sfx collideSfx ;
- Sfx crashSfx ;
- Sfx introSfx ;
- Sfx lastlapSfx ;
- Sfx motorSfx ;
- Sfx startSfx ;
- Sfx toneSfx ;
- Sfx squealSfx ;
-
-
-
- /*------------------------------------------------------------------------------
- * Main routine.
- *----------------------------------------------------------------------------*/
- void
- main(
- int argc,
- char **argv
- )
- {
- int n ;
- Arg args[2] ;
-
- /*
- * Get basename.
- */
- if( ( basename = strrchr( argv[0], '/' ) ) == NULL )
- basename = argv[0] ;
- else
- basename++ ;
-
- srand( (unsigned int)getpid() ) ;
-
- topLevel = XtAppInitialize( &appContext, "Vroom", NULL, 0,
- &argc, argv, fallbacks, NULL, 0 ) ;
- n = 0 ;
- XtSetArg( args[n], XmNallowShellResize, True ) ; n++ ;
- XtSetValues( topLevel, args, n ) ;
-
- XtGetApplicationResources( topLevel, (XtPointer)&AppRes, resources,
- XtNumber( resources ), NULL, 0 ) ;
-
- createIntroWindow( topLevel ) ;
-
- determineMyName() ;
-
- initRobotNames() ;
-
- initTime() ;
-
- #ifdef DEBUG
- if( argc == 2 )
- {
- sscanf( argv[1], "%x", &myHostId ) ;
- if( myHostId == 0 )
- {
- fprintf( stderr, "usage: %s [hex_ip_address]\n",
- basename ) ;
- exit( 1 ) ;
- }
- }
- else
- {
- myHostId = gethostid() ;
- }
- #else
- myHostId = gethostid() ;
- #endif /* DEBUG */
-
- /*
- * Set umask to 0 for writing out records.
- */
- umask( 0 ) ;
-
- setAdminForm( playModeForm ) ;
- XtRealizeWidget( topLevel ) ;
- startedX = 1 ;
- getDefaultDataDir() ;
- unbusyCursor() ;
- if( AppRes.audio )
- {
- initSound() ;
- }
- XtAppMainLoop( appContext ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Make the main window.
- *----------------------------------------------------------------------------*/
- static void
- createMainWindow(
- Widget parent,
- Dimension w,
- Dimension h
- )
- {
- int n ;
- Widget base ;
- Widget frame ;
- Widget menuBar ;
- Widget menuPane ;
- Widget cascade ;
- Arg args[10] ;
-
- /*
- * Create the mother form.
- */
- n = 0 ;
- XtSetArg( args[n], XmNwidth, w ) ; n++ ;
- XtSetArg( args[n], XmNheight, h ) ; n++ ;
- mainWindow = XtCreateWidget( "main", xmMainWindowWidgetClass,
- parent, args, n ) ;
-
- n = 0 ;
- base = XtCreateManagedWidget( "base", xmFormWidgetClass,
- mainWindow, args, n ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNshadowType, XmSHADOW_IN ) ; n++ ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
- frame = XtCreateManagedWidget( "oglFrame", xmFrameWidgetClass,
- base, args, n ) ;
-
- /*
- * Create main OpenGL widget.
- */
- n = 0 ;
- createMainOglWidget( frame, args, n ) ;
-
- /*
- * Create the message label.
- */
- n = 0 ;
- XtSetArg( args[n], XmNshadowType, XmSHADOW_IN ) ; n++ ;
- XtSetArg( args[n], XmNshadowThickness, 2 ) ; n++ ;
- frame = XtCreateManagedWidget( "frame", xmFrameWidgetClass,
- mainWindow, args, n ) ;
-
- n = 0 ;
- msgLabel = XtCreateManagedWidget( "msgLabel", xmLabelWidgetClass,
- frame, args, n ) ;
-
- /*
- * Create menu bar.
- */
- n = 0 ;
- menuBar = XmCreateMenuBar( mainWindow, "menuBar", args, n ) ;
- XtManageChild( menuBar ) ;
-
- /*
- * Create first pull-down menu.
- */
- menuPane = createMenu( menuBar, "System" ) ;
-
- /*
- * Create entries in menu.
- */
- addMenuPushButton( menuPane, "About...", args, 0,
- aboutCB, NULL ) ;
-
- addMenuPushButton( menuPane, "Quit", args, 0,
- exitCB, 0 ) ;
-
- /*
- * Create Help button (not menu).
- */
- n = 0 ;
- cascade = XtCreateManagedWidget( "Help", xmCascadeButtonWidgetClass,
- menuBar, args, n ) ;
- XtAddCallback( cascade, XmNactivateCallback, showRaceHelpCB, NULL ) ;
-
- /*
- * Inform menu bar about which widget should be displayed in the
- * help button position (far right side).
- */
- n = 0 ;
- XtSetArg( args[n], XmNmenuHelpWidget, cascade ) ; n++ ;
- XtSetValues( menuBar, args, n ) ;
-
- /*
- * Define main window areas.
- */
- n = 0 ;
- XtSetArg( args[n], XmNmessageWindow, frame ) ; n++ ;
- XtSetArg( args[n], XmNmenuBar, menuBar ) ; n++ ;
- XtSetArg( args[n], XmNworkWindow, base ) ; n++ ;
- XtSetValues( mainWindow, args, n ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Make the main intro window.
- *----------------------------------------------------------------------------*/
- static void
- createIntroWindow(
- Widget parent
- )
- {
- int n ;
- Arg args[10] ;
- XmString str ;
- Widget oglFrame ;
-
- /*
- * Create the mother form.
- */
- n = 0 ;
- XtSetArg( args[n], XmNfractionBase, 100 ) ; n++ ;
- introWindow = XtCreateWidget( "introForm", xmFormWidgetClass,
- parent, args, n ) ;
-
- controlIntroWindow( 1 ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_NONE ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
- messageForm = XtCreateManagedWidget( "messageForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_POSITION ) ; n++ ;
- XtSetArg( args[n], XmNrightPosition, 50 ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNbottomWidget, messageForm ) ; n++ ;
- playModeForm = XtCreateWidget( "playModeForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- localCourseForm = XtCreateWidget( "localCourseForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- serverCourseForm = XtCreateWidget( "serverCourseForm",
- xmFormWidgetClass, introWindow, args, n ) ;
-
- serverForm = XtCreateWidget( "serverForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- resultsForm = XtCreateWidget( "resultsForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- previewForm = XtCreateWidget( "previewForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- skillForm = XtCreateWidget( "skillForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- courseVoteForm = XtCreateWidget( "courseVoteForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- nameForm = XtCreateWidget( "nameForm", xmFormWidgetClass,
- introWindow, args, n ) ;
-
- str = XmStringCreateLocalized( "Waiting for other players to choose "
- "a course." ) ;
- n = 0 ;
- XtSetArg( args[n], XmNlabelString, str ) ; n++ ;
- XtSetArg( args[n], XmNalignment, XmALIGNMENT_CENTER ) ; n++ ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
- XtCreateManagedWidget( "label", xmLabelWidgetClass,
- courseVoteForm, args, n ) ;
- XmStringFree( str ) ;
-
- createPlayModeChooser( playModeForm ) ;
-
- /*
- * Create the frame for the intro OpenGL window.
- */
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_POSITION ) ; n++ ;
- XtSetArg( args[n], XmNleftPosition, 50 ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNbottomWidget, messageForm ) ; n++ ;
- XtSetArg( args[n], XmNshadowType, XmSHADOW_IN ) ; n++ ;
- XtSetArg( args[n], XmNshadowThickness, 3 ) ; n++ ;
- XtSetArg( args[n], XmNwidth, 400 ) ; n++ ;
- XtSetArg( args[n], XmNheight, 400 ) ; n++ ;
- oglFrame = XtCreateManagedWidget( "introOglFrame", xmFrameWidgetClass,
- introWindow, args, n ) ;
-
- /*
- * Create the OpenGL widget for displaying the intro graphic.
- */
- createIntroOglWidget( oglFrame, args, 0 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Exit program callback function definition.
- *----------------------------------------------------------------------------*/
- void
- exitCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData )
- {
- if( playMode == VROOM_TEAM )
- {
- teamExit() ;
- }
- exit( (int)clientData ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Print string callback function definition.
- *----------------------------------------------------------------------------*/
- void
- printCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData )
- {
- printf( "printCB: `%s'\n", (char *)clientData ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Add a button and assign the activation callback procedure.
- *----------------------------------------------------------------------------*/
- Widget
- addMenuPushButton(
- Widget parent,
- char *label,
- Arg args[],
- int n,
- XtCallbackProc cb,
- XtPointer callData
- )
- {
- Widget button ;
-
- button = XtCreateManagedWidget( label, xmPushButtonWidgetClass,
- parent, args, n ) ;
- if( cb != NULL )
- {
- XtAddCallback( button, XmNactivateCallback, cb, callData ) ;
- }
-
- return( button ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Create a pull-down menu.
- *----------------------------------------------------------------------------*/
- static Widget
- createMenu(
- Widget menuBar,
- char *label
- )
- {
- int n ;
- Arg args[10] ;
- Widget menuPane ;
-
- /*
- * Create holder for first pull-down menu.
- */
- n = 0 ;
- XtSetArg( args[n], XmNisHomogeneous, False ) ; n++ ;
- menuPane = XmCreatePulldownMenu( menuBar, "menuPane", args, n ) ;
-
- /*
- * Connect menu to menu bar.
- */
- n = 0 ;
- XtSetArg( args[n], XmNsubMenuId, menuPane ) ; n++ ;
- (void)XtCreateManagedWidget( label, xmCascadeButtonWidgetClass,
- menuBar, args, n ) ;
-
- return( menuPane ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Display an information string.
- *----------------------------------------------------------------------------*/
- void
- postInfo(
- XtCallbackProc callback,
- XtPointer userData,
- char *fmt,
- ...
- )
- {
- va_list args ;
- char msg[1024] ;
-
- va_start( args, fmt ) ;
- if( startedX )
- {
- vsprintf( msg, fmt, args ) ;
-
- showMessage( msg, XmDIALOG_INFORMATION, callback, userData ) ;
- }
- else
- {
- vprintf( fmt, args ) ;
- }
- va_end( args ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Handle a minor error.
- *----------------------------------------------------------------------------*/
- void
- minorError(
- XtCallbackProc callback,
- XtPointer userData,
- char *fmt,
- ...
- )
- {
- va_list args ;
- char msg[512] ;
-
- va_start( args, fmt ) ;
- if( startedX )
- {
- vsprintf( msg, fmt, args ) ;
-
- showMessage( msg, XmDIALOG_WARNING, callback, userData ) ;
- }
- else
- {
- vprintf( fmt, args ) ;
- }
- va_end( args ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Handle a fatal error.
- *----------------------------------------------------------------------------*/
- void
- fatalError(
- char *fmt,
- ...
- )
- {
- va_list args ;
- char msg[512] ;
- XEvent event ;
-
- va_start( args, fmt ) ;
- if( startedX )
- {
- vsprintf( msg, fmt, args ) ;
-
- showMessage( msg, XmDIALOG_ERROR, exitCB, (XtPointer)1 ) ;
-
- while( 1 )
- {
- XtAppNextEvent( appContext, &event ) ;
- XtDispatchEvent( &event ) ;
- }
- }
- else
- {
- vprintf( fmt, args ) ;
- printf( "\n" ) ;
- exit( 1 ) ;
- }
- va_end( args ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Try to allocate memory, exiting if failure occurs.
- *----------------------------------------------------------------------------*/
- void *
- myMalloc(
- size_t size
- )
- {
- void *ptr ;
-
- if( ( ptr = malloc( size ) ) == NULL )
- {
- fatalError( "Out of memory." ) ;
- }
-
- return( ptr ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Try to reallocate memory, exiting if failure occurs.
- *----------------------------------------------------------------------------*/
- void *
- myRealloc(
- void *ptr,
- size_t size
- )
- {
- void *newPtr ;
-
- if( ( newPtr = realloc( ptr, size ) ) == NULL )
- {
- fatalError( "Out of memory." ) ;
- }
-
- return( newPtr ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Unmanage a widget.
- *----------------------------------------------------------------------------*/
- void PopDownCB(
- Widget callingWidget,
- Widget doomedWidget,
- caddr_t call_data
- )
- {
- XtUnmanageChild( doomedWidget ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Extract a normal string from an XmString.
- *----------------------------------------------------------------------------*/
- char *
- extractNormalString(
- XmString cs
- )
- {
- XmStringContext context;
- XmStringCharSet charset;
- XmStringDirection direction;
- Boolean separator;
- static char *primitive_string;
-
- XmStringInitContext( &context, cs ) ;
- XmStringGetNextSegment( context, &primitive_string, &charset,
- &direction, &separator ) ;
- XmStringFreeContext( context ) ;
- return( (char *)primitive_string ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Normalize a 2D vector.
- *----------------------------------------------------------------------------*/
- float
- normalizeVec2(
- float v[2]
- )
- {
- float s ;
-
- s = v[0] * v[0] + v[1] * v[1] ;
-
- if( s > 0.0f )
- {
- s = sqrtf( s ) ;
- v[0] /= s ;
- v[1] /= s ;
- }
-
- return( s ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show an information message.
- *----------------------------------------------------------------------------*/
- static void
- showMessage(
- char *msg,
- unsigned char dialogType,
- XtCallbackProc callback,
- XtPointer userData
- )
- {
- int n ;
- Arg args[10] ;
- XmString msgStr ;
- XmString titleStr ;
- Widget msgBox ;
- Widget button ;
-
- msgStr = XmStringCreateLtoR( msg, XmFONTLIST_DEFAULT_TAG ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNmessageString, msgStr ) ; n++ ;
- switch( dialogType )
- {
- case XmDIALOG_INFORMATION :
- default :
- titleStr = XmStringCreateLocalized( "Info" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- msgBox = XmCreateInformationDialog( topLevel,
- "msgBox", args, n ) ;
- break ;
-
- case XmDIALOG_ERROR :
- titleStr = XmStringCreateLocalized( "Error" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- XtSetArg( args[n], XmNdialogStyle,
- XmDIALOG_FULL_APPLICATION_MODAL ) ; n++ ;
- msgBox = XmCreateErrorDialog( topLevel,
- "msgBox", args, n ) ;
- break ;
-
- case XmDIALOG_WARNING :
- titleStr = XmStringCreateLocalized( "Warning" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- XtSetArg( args[n], XmNdialogStyle,
- XmDIALOG_FULL_APPLICATION_MODAL ) ; n++ ;
- msgBox = XmCreateWarningDialog( topLevel,
- "msgBox", args, n ) ;
- break ;
-
- case XmDIALOG_MESSAGE :
- titleStr = XmStringCreateLocalized( "Message" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- msgBox = XmCreateMessageDialog( topLevel,
- "msgBox", args, n ) ;
- break ;
- }
-
- if( callback != NULL )
- {
- XtAddCallback( msgBox, XmNokCallback, callback, userData ) ;
- }
-
- button = XmMessageBoxGetChild( msgBox, XmDIALOG_CANCEL_BUTTON ) ;
- XtUnmanageChild( button ) ;
- button = XmMessageBoxGetChild( msgBox, XmDIALOG_HELP_BUTTON ) ;
- XtUnmanageChild( button ) ;
-
- XmStringFree( msgStr ) ;
- XmStringFree( titleStr ) ;
-
- XtManageChild( msgBox ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set up work procedures.
- *----------------------------------------------------------------------------*/
- void
- setWorkProc(
- long wpMask,
- int mode
- )
- {
- /*
- * If add a procedure...
- */
- if( mode )
- {
- workProcMask |= wpMask ;
- /*
- * If the master work procedure isn't running, start it.
- */
- if( workProcMask != 0 && lastWorkProc == 0 )
- {
- lastWorkProc = XtAppAddWorkProc( appContext,
- masterWorkProc, NULL ) ;
- }
- }
- /*
- * Remove a work procedure.
- */
- else
- {
- workProcMask &= ~wpMask ;
- /*
- * If no more work procedures, signal master work proc to end.
- */
- if( workProcMask == 0 && lastWorkProc != 0 )
- {
- lastWorkProc = 0 ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Master work proc.
- *----------------------------------------------------------------------------*/
- static Boolean
- masterWorkProc(
- XtPointer clientData
- )
- {
- static float lastLoopTime = 0.0f ;
-
- #if DEBUG
- switch( freeTime )
- {
- case 1 :
- currentTime = gameTime() ;
- break ;
-
- case 0 :
- currentTime += 0.1f ;
- break ;
-
- default:
- break ;
- }
- #else
- currentTime = gameTime() ;
- #endif /* DEBUG */
-
- if( workProcMask & VROOM_WP_RUN_SERVER )
- {
- /*
- * Throttle server back to 15 frames per second to avoid
- * flooding the net (and slower clients).
- */
- if( currentTime - lastLoopTime > 0.066f )
- {
- #ifdef DEBUG
- calculateFrameRate() ;
- #endif /* DEBUG */
- serverRun() ;
- lastLoopTime = currentTime ;
- }
- }
-
- if( workProcMask & VROOM_WP_RUN_CLIENT )
- {
- clientRun() ;
- }
-
- if( workProcMask & VROOM_WP_SOLO )
- {
- /*
- * Throttle server back to 30 frames per second to avoid
- * some jumpiness on Extremes on small courses.
- */
- if( currentTime - lastLoopTime > 0.033f )
- {
- #ifdef DEBUG
- calculateFrameRate() ;
- #endif /* DEBUG */
- soloLoop() ;
- lastLoopTime = currentTime ;
- }
- }
-
- if( workProcMask & VROOM_WP_READ_SERVER )
- {
- serverRead() ;
- }
-
- if( workProcMask & VROOM_WP_TIME_GRAPHICS )
- {
- timeGraphics() ;
- }
-
- if( workProcMask & VROOM_WP_FIND_SERVER )
- {
- serverFind() ;
- }
-
- #ifdef DEBUG
- checkGlError( basename ) ;
- #endif /* DEBUG */
-
- return( lastWorkProc == 0 ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Callback to manage a widget.
- *----------------------------------------------------------------------------*/
- void
- popUpCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- XtManageChild( (Widget)clientData ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Start the time trials.
- *----------------------------------------------------------------------------*/
- void
- startTimeTrials(
- int skipTrial
- )
- {
- controlIntroWindow( 0 ) ;
-
- controlMainWindow( 1 ) ;
-
- defaultLod() ;
- currentTime = gameTime() ;
- if( playMode == VROOM_SOLO )
- {
- initSoloGame( skipTrial ) ;
- }
- else
- {
- initTeamGame() ;
- }
-
- noteTrackRecords() ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Manage and unmanage the main window.
- *----------------------------------------------------------------------------*/
- void
- controlMainWindow(
- int show
- )
- {
- int n ;
- Arg arg[2] ;
- static int init = 0 ;
- static Dimension w ;
- static Dimension h ;
-
- if( init == 0 )
- {
- init = 1 ;
- w = AppRes.mainWidth ;
- h = AppRes.mainHeight ;
- createMainWindow( topLevel, w, h ) ;
-
- if( show == 0 )
- {
- return ;
- }
- else
- {
- XtManageChild( mainWindow ) ;
- }
- }
- else
- {
- if( show )
- {
- XtManageChild( mainWindow ) ;
- n = 0 ;
- XtSetArg( arg[n], XmNwidth, w ) ; n++ ;
- XtSetArg( arg[n], XmNheight, h ) ; n++ ;
- XtSetValues( topLevel, arg, n ) ;
- }
- else
- {
- n = 0 ;
- XtSetArg( arg[n], XmNwidth, &w ) ; n++ ;
- XtSetArg( arg[n], XmNheight, &h ) ; n++ ;
- XtGetValues( mainWindow, arg, n ) ;
- XtUnmanageChild( mainWindow ) ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Manage and unmanage the intro window.
- *----------------------------------------------------------------------------*/
- void
- controlIntroWindow(
- int show
- )
- {
- int n ;
- Arg arg[2] ;
- static int init = 0 ;
- static Dimension w = 800 ;
- static Dimension h = 400 ;
-
- if( init == 0 )
- {
- init = 1 ;
-
- if( show == 1 )
- {
- XtManageChild( introWindow ) ;
- }
- }
- else
- {
- if( show )
- {
- setIntroCarShot() ;
- XtManageChild( introWindow ) ;
- n = 0 ;
- XtSetArg( arg[n], XmNwidth, w ) ; n++ ;
- XtSetArg( arg[n], XmNheight, h ) ; n++ ;
- XtSetValues( topLevel, arg, n ) ;
- }
- else
- {
- n = 0 ;
- XtSetArg( arg[n], XmNwidth, &w ) ; n++ ;
- XtSetArg( arg[n], XmNheight, &h ) ; n++ ;
- XtGetValues( introWindow, arg, n ) ;
- XtUnmanageChild( introWindow ) ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the cursor to the busy symbol.
- *----------------------------------------------------------------------------*/
- void
- busyCursor(
- void
- )
- {
- static Cursor c = NULL ;
-
- if( c == NULL )
- {
- c = XCreateFontCursor( XtDisplay( topLevel ), XC_watch ) ;
- }
- XDefineCursor( XtDisplay( topLevel ), XtWindow( topLevel ), c ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the cursor to the arrow symbol.
- *----------------------------------------------------------------------------*/
- void
- unbusyCursor(
- void
- )
- {
- static Cursor c = NULL ;
-
- if( c == NULL )
- {
- c = XCreateFontCursor( XtDisplay( topLevel ), XC_left_ptr ) ;
- }
- XDefineCursor( XtDisplay( topLevel ), XtWindow( topLevel ), c ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set message string.
- *----------------------------------------------------------------------------*/
- void
- setMessage(
- char *fmt,
- ...
- )
- {
- va_list args ;
- char msg[1024] ;
- Arg arg[1] ;
- XmString str ;
-
- va_start( args, fmt ) ;
- vsprintf( msg, fmt, args ) ;
-
- str = XmStringCreateLocalized( msg ) ;
- XtSetArg( arg[0], XmNlabelString, str ) ;
- XtSetValues( msgLabel, arg, 1 ) ;
- XmStringFree( str ) ;
-
- va_end( args ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Convert time to min:sec.tenths format string.
- *----------------------------------------------------------------------------*/
- char *
- raceTimeString(
- float t,
- int *length
- )
- {
- int min ;
- int sec ;
- int tenths ;
- float tt ;
- static char str[9] ;
-
- tt = ABSFUNC( t ) ;
- min = (int)( tt / 60.0f ) ;
- tt -= 60.0f * min ;
- sec = (int)tt ;
- tenths = (int)( 10.0f * ( tt - sec ) ) ;
-
- min = min % 100 ;
- str[0] = '-' ;
- str[1] = '0' + min / 10 ;
- str[2] = '0' + min % 10 ;
- str[3] = ':' ;
- str[4] = '0' + sec / 10 ;
- str[5] = '0' + sec % 10 ;
- str[6] = '.' ;
- str[7] = '0' + tenths ;
- str[8] = '\0' ;
-
- if( t >= 0.0f )
- {
- *length = 8 ;
- return( str + 1 ) ;
- }
- else
- {
- *length = 9 ;
- return( str ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Convert time to min:sec.hundreths format string.
- *----------------------------------------------------------------------------*/
- char *
- longRaceTimeString(
- float t,
- int *length
- )
- {
- int min ;
- int sec ;
- int huns ;
- float tt ;
- static char str[10] ;
-
- tt = ABSFUNC( t ) ;
- min = (int)( tt / 60.0f ) ;
- tt -= 60.0f * min ;
- sec = (int)tt ;
- huns = (int)( 100.0f * ( tt - sec ) ) ;
-
- min = min % 100 ;
- str[0] = '-' ;
- str[1] = '0' + min / 10 ;
- str[2] = '0' + min % 10 ;
- str[3] = ':' ;
- str[4] = '0' + sec / 10 ;
- str[5] = '0' + sec % 10 ;
- str[6] = '.' ;
- str[7] = '0' + huns / 10 ;
- str[8] = '0' + huns % 10 ;
- str[9] = '\0' ;
-
- if( t >= 0.0f )
- {
- *length = 8 ;
- return( str + 1 ) ;
- }
- else
- {
- *length = 9 ;
- return( str ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Pick a random number and return whether it is below a threshhold number.
- *----------------------------------------------------------------------------*/
- Boolean
- randomChoice(
- float threshhold
- )
- {
- float x ;
-
- x = (float)( rand() % 0x0ff ) / (float)( 0x0ff ) ;
-
- return( x < threshhold ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Determine my player's name.
- *----------------------------------------------------------------------------*/
- static void
- determineMyName(
- void
- )
- {
- char *s ;
- char tmp[L_cuserid] ;
-
- if( ( s = getenv( "VROOM_NAME" ) ) != NULL )
- {
- myName = strdup( s ) ;
- }
- else if( AppRes.name != NULL && strlen( AppRes.name ) > 0 )
- {
- myName = AppRes.name ;
- }
- else
- {
- cuserid( tmp ) ;
-
- myName = strdup( tmp ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Determine the default data directory.
- *----------------------------------------------------------------------------*/
- static void
- getDefaultDataDir(
- void
- )
- {
- char *d ;
- int recDirMode ;
-
- if( ( d = getenv( "VROOM_DIR" ) ) != NULL )
- {
- defaultDataDir = d ;
- }
- else if( AppRes.defaultDataDir != NULL &&
- strlen( AppRes.defaultDataDir ) > 0 )
- {
- defaultDataDir = AppRes.defaultDataDir ;
- }
- if( defaultDataDir == NULL || strlen( defaultDataDir ) == 0 )
- {
- defaultDataDir = strdup( VROOM_DEFAULT_DIR ) ;
- }
-
- if( ( d = getenv( "VROOM_REC_DIR" ) ) != NULL )
- {
- recDirMode = 1 ;
- defaultRecDir = d ;
- }
- else if( AppRes.defaultRecDir != NULL &&
- strlen( AppRes.defaultRecDir ) > 0 )
- {
- recDirMode = 2 ;
- defaultRecDir = AppRes.defaultRecDir ;
- }
- if( defaultRecDir == NULL || strlen( defaultRecDir ) == 0 )
- {
- recDirMode = 0 ;
- defaultRecDir = strdup( VROOM_DEFAULT_REC_DIR ) ;
- }
-
- /*
- * Make sure directories exist and are readable.
- */
- if( access( defaultDataDir, F_OK ) < 0 )
- {
- fatalError( "Can not access data directory:\n\n%s\n\n"
- "Check the setting of the VROOM_DIR environment\n"
- "variable.", defaultDataDir ) ;
- }
-
- if( access( defaultRecDir, F_OK | W_OK ) < 0 )
- {
- switch( recDirMode )
- {
- case 0 :
- minorError( NULL, NULL,
- "Can not write to the default records directory:\n"
- "\n\t%s\n\n"
- "You will be unable to save any track records. You\n"
- "can set the VROOM_REC_DIR environment variable or\n"
- "Vroom*defaultRecDir resource to override the default\n"
- "directory setting.", defaultRecDir ) ;
- break ;
-
- case 1 :
- minorError( NULL, NULL,
- "Can not write to the records directory:\n"
- "\n\t%s\n\n"
- "specified by the environment variable VROOM_REC_DIR.\n"
- "You will be unable to save any track records.",
- defaultRecDir ) ;
- break ;
-
- case 2 :
- minorError( NULL, NULL,
- "Can not write to the records directory:\n"
- "\n\t%s\n\n"
- "specified by the resource value Vroom*defaultRecDir.\n"
- "You will be unable to save any track records.",
- defaultRecDir ) ;
- break ;
- }
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Help program callback function definition.
- *----------------------------------------------------------------------------*/
- void
- helpCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- Widget help ;
- char **helpFileName = (char **)clientData ;
- char *helpMessage = NULL ;
-
- if( ( helpMessage = getHelpMessage( helpFileName[0] ) ) == NULL )
- {
- return ;
- }
-
- help = createHelpWidget( w, helpMessage, helpCB, &(helpFileName[1]) ) ;
-
- free( helpMessage ) ;
-
- XtManageChild( help ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Load in a help file.
- *----------------------------------------------------------------------------*/
- static char *
- getHelpMessage(
- char *file
- )
- {
- FILE *f ;
- char *helpMessage = NULL ;
- struct stat st ;
- char name[FILENAME_MAX] ;
-
- sprintf( name, "%s/%s", defaultDataDir, file ) ;
-
- if( ( f = fopen( name, "r" ) ) == NULL )
- {
- minorError( NULL, NULL, "Could not locate help file: `%s'.\n"
- "Set the environment variable, VROOM_DIR, to "
- "indicate the correct directory.", name ) ;
- }
- else if( fstat( fileno(f), &st ) == -1 )
- {
- minorError( NULL, NULL, "Could not determine the size of the"
- " help file:\n`%s'.", name ) ;
- }
- else if( ( helpMessage = (char *)malloc( st.st_size + 1 ) ) == NULL )
- {
- minorError( NULL, NULL, "Can not allocate enough space to read"
- " in the help file." ) ;
- }
- else if( fread( helpMessage, sizeof( char ), st.st_size, f )
- != st.st_size )
- {
- minorError( NULL, NULL, "Error reading the help file `%s'.",
- name ) ;
- free( helpMessage ) ;
- helpMessage = NULL ;
- }
- else
- {
- if( helpMessage[st.st_size-1] == '\n' )
- {
- helpMessage[st.st_size-1] = '\0' ;
- }
- else
- {
- helpMessage[st.st_size] = '\0' ;
- }
- }
-
- return( helpMessage ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Create the help pop-up window.
- *----------------------------------------------------------------------------*/
- static Widget
- createHelpWidget(
- Widget parent,
- char *helpMessage,
- XtCallbackProc nextHelp,
- char **helpFileName
- )
- {
- int n ;
- Widget helpButton ;
- XmString helpStr ;
- XmString titleStr ;
- int nLines ;
- Widget help ;
- Arg args[10] ;
-
- nLines = numberOfLines( helpMessage ) ;
-
- if( nLines > MAX_VISIBLE_HELP_LINES )
- {
- help = createScrolledTextDialog( parent, helpMessage, nextHelp,
- helpFileName ) ;
- }
- else
- {
- n = 0 ;
- helpStr = XmStringCreateLtoR( helpMessage,
- XmFONTLIST_DEFAULT_TAG ) ;
- XtSetArg( args[n], XmNmessageString, helpStr ) ; n++ ;
- titleStr = XmStringCreateLocalized( "Help" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- help = XmCreateInformationDialog( parent, "helpPage", args, n );
- XmStringFree( helpStr ) ;
- XmStringFree( titleStr ) ;
- if( helpFileName[0] != NULL )
- {
- XtAddCallback( help, XmNhelpCallback, helpCB,
- helpFileName ) ;
- }
- else
- {
- helpButton = XmMessageBoxGetChild( help,
- XmDIALOG_HELP_BUTTON );
- XtUnmanageChild( helpButton ) ;
- }
-
- XtUnmanageChild( XmMessageBoxGetChild( help,
- XmDIALOG_CANCEL_BUTTON ) );
- }
-
- return( help ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Determine the number of lines in a string.
- *----------------------------------------------------------------------------*/
- static int
- numberOfLines(
- const char *text
- )
- {
- int nLines = 0 ;
-
- while( *text != '\0' )
- {
- if( *(text++) == '\n' ) nLines++ ;
- }
-
- return( nLines ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Make a dialog window containing scrolled text.
- *----------------------------------------------------------------------------*/
- static Widget
- createScrolledTextDialog(
- Widget parent,
- char *helpMessage,
- XtCallbackProc nextHelp,
- char **helpFileName
- )
- {
- Widget help ;
- Widget helpText ;
- Widget separator ;
- Widget okButton ;
- Widget helpButton ;
- Widget rowOfButtons ;
- XmString titleStr ;
- int n ;
- Arg args[15] ;
-
- n = 0 ;
- XtSetArg( args[n], XmNautoUnmanage, False ) ; n++ ;
- titleStr = XmStringCreateLocalized( "Help" ) ;
- XtSetArg( args[n], XmNdialogTitle, titleStr ) ; n++ ;
- help = XmCreateFormDialog( parent, "helpPage", args, n ) ;
- XmStringFree( titleStr ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- XtSetArg( args[n], XmNwidth, 500 ) ; n++ ;
- XtSetArg( args[n], XmNeditMode, XmMULTI_LINE_EDIT ) ; n++ ;
- XtSetArg( args[n], XmNwordWrap, True ) ; n++ ;
- XtSetArg( args[n], XmNrows, MAX_VISIBLE_HELP_LINES ) ; n++ ;
- helpText = XmCreateScrolledText( help, "helpText", args, n ) ;
- XtManageChild( helpText ) ;
- XmTextSetString( helpText, helpMessage ) ;
- n = 0 ;
- XtSetArg( args[n], XmNeditable, False ) ; n++ ;
- XtSetValues( helpText, args, n ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, helpText ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_NONE ) ; n++ ;
- separator = XtCreateManagedWidget( "separator", xmSeparatorWidgetClass,
- help, args, n );
-
- n = 0 ;
- XtSetArg( args[n], XmNspacing, 10 ) ; n++ ;
- XtSetArg( args[n], XmNborderWidth, 0 ) ; n++ ;
- XtSetArg( args[n], XmNtopAttachment, XmATTACH_WIDGET ) ; n++ ;
- XtSetArg( args[n], XmNtopWidget, separator ) ; n++ ;
- XtSetArg( args[n], XmNleftAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNrightAttachment, XmATTACH_FORM ) ; n++ ;
- XtSetArg( args[n], XmNbottomAttachment, XmATTACH_FORM ) ; n++ ;
- rowOfButtons = XtCreateManagedWidget( "helpButtons",
- xsRowWidgetClass, help, args, n ) ;
-
- n = 0 ;
- XtSetArg( args[n], XmNmarginHeight, 5 ) ; n++ ;
- XtSetArg( args[n], XmNmarginWidth, 5 ) ; n++ ;
- okButton = XtCreateManagedWidget( "Ok", xmPushButtonWidgetClass,
- rowOfButtons, args, n ) ;
- XtAddCallback( okButton, XmNactivateCallback, destroyWidgetCB, help ) ;
-
- if( helpFileName[0] != NULL )
- {
- helpButton = XtCreateManagedWidget( "Help",
- xmPushButtonWidgetClass, rowOfButtons,
- args, n ) ;
- XtAddCallback( helpButton, XmNactivateCallback, nextHelp,
- helpFileName ) ;
- }
- return( help ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Destroy a widget.
- *----------------------------------------------------------------------------*/
- static void
- destroyWidgetCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- XtDestroyWidget( (Widget)clientData ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Show about message.
- *----------------------------------------------------------------------------*/
- void
- aboutCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- postInfo( NULL, NULL, "VROOM - slot cars of the future\n\n"
- "Chris Fouts - May 1994 - Version 1.1" ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Pop-up help file on racing.
- *----------------------------------------------------------------------------*/
- void
- showRaceHelpCB(
- Widget w,
- XtPointer clientData,
- XtPointer callData
- )
- {
- static char *localHelpFiles[] = { "localrace.help", NULL } ;
- static char *netHelpFiles[] = { "netrace.help", NULL } ;
-
- if( playMode == VROOM_SOLO )
- {
- helpCB( mainWindow, (XtPointer)localHelpFiles, NULL ) ;
- }
- else
- {
- helpCB( mainWindow, (XtPointer)netHelpFiles, NULL ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Return the default time-to-live setting for server broadcasts.
- *----------------------------------------------------------------------------*/
- int
- getTtl(
- void
- )
- {
- if( AppRes.ttl < 1 )
- {
- AppRes.ttl = 1 ;
- }
- else if( AppRes.ttl > 32 )
- {
- AppRes.ttl = 32 ;
- }
-
- return( AppRes.ttl ) ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Initialize the sound routines.
- *----------------------------------------------------------------------------*/
- static void
- initSound(
- void
- )
- {
- int err ;
-
- err = sfxInit( defaultDataDir, 3 ) ;
-
- if( err == SFX_ERR_NO_PORTS_AVAIL )
- {
- postInfo( NULL, NULL, "No audio ports are available." );
- }
- else if( err == SFX_ERR_NO_SPROC )
- {
- postInfo( NULL, NULL, "Unable to execute sound "
- "process." );
- }
- else if( err == SFX_ERR_NO_MEM )
- {
- postInfo( NULL, NULL, "No memory available for sound"
- "data." );
- }
- else if( err > 0 )
- {
- introSfx = sfxLoad( "intro.aifc" ) ;
- toneSfx = sfxLoad( "tone1.aifc" ) ;
- startSfx = sfxLoad( "start.aifc" ) ;
- crashSfx = sfxLoad( "crash.aifc" ) ;
- alertSfx = sfxLoad( "alert.aifc" ) ;
- collideSfx = sfxLoad( "collide.aifc" ) ;
- cheerSfx = sfxLoad( "cheers.aifc" ) ;
- changeLaneSfx = sfxLoad( "changelane.aifc" ) ;
- lastlapSfx = sfxLoad( "lastlap.aifc" ) ;
- if( err > 1 )
- {
- squealSfx = sfxLoad( "squeal.aifc" ) ;
- sfxLoop( squealSfx ) ;
- if( err > 2 )
- {
- motorSfx = sfxLoad( "motor.aifc" ) ;
- sfxLoop( motorSfx ) ;
- sfxPitchBend( motorSfx, 0.0f, 1.0f, 1.0f,
- 2.0f, 1.1f, 20 ) ;
- }
- }
- sfxPlay( introSfx ) ;
- }
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Set the admininistration form (unmanage previous form).
- *----------------------------------------------------------------------------*/
- void
- setAdminForm(
- Widget newForm
- )
- {
- static Widget oldForm = NULL ;
-
- if( oldForm != NULL )
- {
- XtUnmanageChild( oldForm ) ;
- }
- XtManageChild( newForm ) ;
-
- oldForm = newForm ;
- }
-
-
-
- /*------------------------------------------------------------------------------
- * Calculate the current frame rate (over 1 second intervals).
- *----------------------------------------------------------------------------*/
- static void
- calculateFrameRate(
- void
- )
- {
- static float lastTime = 0.0f ;
- static int nFrames = 0 ;
- static int dTime = 0.0f ;
-
- nFrames++ ;
- if( currentTime - dTime >= 1.0f )
- {
- frameRate = nFrames / ( currentTime - dTime ) ;
- dTime = currentTime ;
- nFrames = 0 ;
- }
-
- lastTime = currentTime ;
- }
-